

var type_map = new Map();
type_map['html_website'] = '纯前端网站'

function create(create_type) {
    var win_obj = document.getElementById('create_console');
    var project_type = document.getElementById('project_type')
    project_type.innerText = type_map[create_type];
    win_obj.style.display='block'

    var create_btn = document.getElementById('create_btn');
    var json = JSON.parse(document.cookie)

    create_btn.onclick = function() {
        var project_name = document.getElementById('project_name').value;
        var check_code = document.getElementById('check').value;
        if (project_name.replaceAll(' ','') == '') {
            showAlert("请填写完整项目名称" , null);
            return;
        }

        var user = json.user;
        var pwd  = json.pwd;

        var xhr = new XMLHttpRequest();
        xhr.open('POST' , remote+'/create/'+user+"/"+pwd+"/"+check_code+"/"+create_type+"/"+project_name , true);
        xhr.send();
        xhr.onload=function() {
            xhr.responseText = xhr.responseText.replaceAll('\n','')
            showAlert(xhr.responseText , 3000)
            if (
                xhr.responseText == '用户名或者密码不正确' || 
                xhr.responseText == '项目创建数量不得多于 3 个项目' ||
                xhr.responseText == '请求过多' ||
                xhr.responseText == '项目已经存在' ||
                xhr.responseText == '验证码错误'
            ) {
                console.log(null)
            }
            else {
                setTimeout(() => {
                    window.location.href='../website_cms.html?name='+project_name
                }, 3000);
            }
        }
    }
}